package com.yurun.controller.admin;

import com.yurun.entity.ScheduleJob;
import com.yurun.model.vo.Result;
import com.yurun.service.ScheduleJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class ScheduleController {
    @Autowired
    ScheduleJobService scheduleJobService;
    /**
     * @Description: 添加任务
     * @Param: scheduleJob
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PostMapping("/job")
    public Result addJob(@RequestBody ScheduleJob scheduleJob){
        scheduleJobService.addJob(scheduleJob);
        return Result.ok("添加任务成功");
    }
    /**
     * @Description: 通过ID-删除任务
     * @Param: id
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @DeleteMapping("/job/id")
    public Result deleteJobById(@RequestParam Long id){
        scheduleJobService.deleteJobById(id);
        return Result.ok("删除任务成功");
    }
    /**
     * @Description: 更新任务
     * @Param: scheduleJob
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PutMapping("/job")
    public Result updateJob(@RequestBody ScheduleJob scheduleJob){
        scheduleJobService.updateJob(scheduleJob);
        return Result.ok("更新任务成功");
    }
    /**
     * @Description: 通过ID更新任务状态
     * @Param: id
	 * @Param  status
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PutMapping("/jobstatus/id")
    public Result updateJobStatusById(@RequestParam Long id,
                                    @RequestParam Boolean status){
        scheduleJobService.updateJobStatusById(id, status);
        return Result.ok("更新任务状态成功");
    }
    /**
     * @Description: 通过ID-获取任务
     * @Param: id
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/job/id")
    public Result getJobById(@RequestParam Long id){
        ScheduleJob object= scheduleJobService.getJobById(id);
        return Result.ok("请求任务成功",object);
    }
    /**
     * @Description: 获取任务列表
     * @Param:
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/joblist")
    public Result getJobList(){
        List<ScheduleJob> object=scheduleJobService.getJobList();
        return Result.ok("请求任务列表成功",object);
    }
}
